
const arrayPrototype = Array.prototype;

export const arrayMethods = Object.create(arrayPrototype)
import {def} from './utils'
const methodsNeedChange = [
    'push',
    'pop',
    'shift',
    'unshift',
    'splice',
    'sort',
    'reverse'
];

methodsNeedChange.forEach(methodsName =>{

    //保存旧方法
    const origin = methodsNeedChange[methodsName]


    def(arrayMethods,methodsName,function (){
        const res = origin.apply(this,arguments)
        let inseted = []
        let args = [...arguments]
        var ob= this.__ob__

        switch (methodsName){
            case 'push':
            case 'shift':
                inseted = args
                break
            case 'splice':
                inseted = args[2]
                break

        }
        if(inseted){
            ob.observeArray(inseted)
        }
        ob.dep.notify()

        return res
    },false)

})